package com.ojoin.trade.t0loan_core.web.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.utils.LogUtils;
import com.ojoin.trade.common.web.dao.BaseDao;
import com.ojoin.trade.common.web.service.impl.BaseServiceImpl;
import com.ojoin.trade.t0loan_core.web.dao.TbPosTranscationLogDao;
import com.ojoin.trade.t0loan_core.web.domain.TbPosTranscationLog;
import com.ojoin.trade.t0loan_core.web.service.PosTranscationLogBaseService;

/**
 * Pos机交易明细记录服务实现
 * @author guoting
 *
 */
@Service
public class PosTranscationLogBaseServiceImpl extends BaseServiceImpl<TbPosTranscationLog> implements
	PosTranscationLogBaseService {

	@Autowired
	private TbPosTranscationLogDao dao;
	
	/**
	 * 查询当日指定支付商户未申请T+1贷款的Pos机交易明细记录 (T0000007)
	 * 查询tb_pos_transcation_log表中交易时间为当日
	 * 且不在tb_t0_status_of_pos_transcation_id表中used_by_loan为Y的记录
	 * 中的支付商户Pos机交易明细记录，记录业务日志
	 */
	@Override
	public List<TbPosTranscationLog> queryAllNoT1LoanPosTransInfoListByPayUserID(
			int joinuserid, String transdate) throws BusinessException {
		LogUtils.getT0loanLog().info("查询当日指定支付商户未申请T+0贷款的Pos机交易明细记录, " +
				"joinuserid->" + joinuserid + ", transdate->" + transdate);
		List<TbPosTranscationLog> selectList = ((TbPosTranscationLogDao)this.getBaseDao()).queryAllNoT1LoanPosTransInfoListByPayUserID(joinuserid, transdate);
		return selectList == null || selectList.size() == 0 ? null : selectList;
	}

	@Override
	protected BaseDao<TbPosTranscationLog> getBaseDao() {
		return dao;
	}

	@Override
	public List<TbPosTranscationLog> queryT0LoanLiveUserHistoryPosTransListByMhtNo(
			String mhtno, Pageable page) throws BusinessException {
		LogUtils.getT0loanLog().info("查询指定商户申请T+0贷款审核通过的九盈用户的当日前30日历史交易列表, " +
				"mhtno->" + mhtno + ", " +
				"pageno" + page.getPageNumber() + ", pagesize->" + page.getPageSize());
		List<TbPosTranscationLog> selectList = ((TbPosTranscationLogDao)this.getBaseDao()).queryT0LoanLiveUserHistoryPosTransListByMhtNo(mhtno, page);
		return selectList == null || selectList.size() == 0 ? null : selectList;
	}

	@Override
	public TbPosTranscationLog queryT1LoanPosTransInfoSumByPayUserID(
			int joinuserid, String transdate) throws BusinessException {
		LogUtils.getT0loanLog().info("查询当日指定支付商户未申请T+1贷款的Pos机交易明细合计值记录, " +
				"joinuserid->" + joinuserid + ", transdate->" + transdate + "");
		return ((TbPosTranscationLogDao)this.getBaseDao()).queryT1LoanPosTransInfoSumByPayUserID(joinuserid, transdate);
	}

	@Override
	public void deleteByIdInBatch(Integer joinuserid, String transdate) throws BusinessException {
		((TbPosTranscationLogDao)this.getBaseDao()).deleteByIdInBatch(joinuserid, transdate);		
	}


}
